package com.song.tools.songtest.convertor;

import com.song.tools.mvc.convertor.AggregationConvertor;
import com.song.tools.songtest.beans.bo.DictionaryBo;
import com.song.tools.songtest.beans.poi.DictionaryExportDto;
import com.song.tools.songtest.beans.poi.DictionaryImportDto;
import com.song.tools.songtest.beans.query.DictionaryQuery;
import com.song.tools.songtest.beans.request.DictionaryQueryRequest;
import com.song.tools.songtest.beans.request.DictionarySaveRequest;
import com.song.tools.songtest.beans.request.DictionaryUpdateRequest;
import com.song.tools.songtest.beans.response.DictionaryQueryResponse;
import com.song.tools.songtest.beans.response.DictionarySaveResponse;
import com.song.tools.songtest.beans.response.DictionaryUpdateResponse;
import com.song.tools.songtest.constants.StatusEnum;
import com.song.tools.songtest.dao.entity.Dictionary;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.ReportingPolicy;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 字典表 转换器
 * </p>
 *
 * @author song tools
 * @since 2024-07-12
 */
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public abstract class DictionaryConvertor implements AggregationConvertor<Dictionary, DictionaryBo, DictionaryQuery, DictionaryQueryRequest, DictionaryQueryResponse,
        DictionarySaveRequest, DictionarySaveResponse, DictionaryUpdateRequest, DictionaryUpdateResponse, DictionaryImportDto, DictionaryExportDto> {

    @Override
    public abstract Dictionary entityBoToEntity(DictionaryBo dictionaryBo);

    @Override
    public abstract DictionaryBo entityToEntityBo(Dictionary dictionary);

    @Override
    public abstract DictionaryQueryResponse entityBoToQueryResponse(DictionaryBo dictionaryBo);

    @Override
    public abstract DictionaryQuery queryRequestToQuery(DictionaryQueryRequest queryRequest);

    @Override
    public abstract DictionaryBo saveRequestToEntityBo(DictionarySaveRequest request);

    @Override
    public abstract DictionarySaveResponse entityBoToSaveResponse(DictionaryBo dictionaryBo);

    @Override
    public abstract DictionaryBo updateRequestToEntityBo(DictionaryUpdateRequest request);

    @Override
    public abstract DictionaryUpdateResponse entityBoToUpdateResponse(DictionaryBo dictionaryBo);

    @Override
    public abstract List<Dictionary> entityBoToEntity(List<DictionaryBo> entityBo);

    @Override
    public abstract List<DictionaryBo> entityToEntityBo(List<Dictionary> entity);

    @Override
    public abstract DictionaryExportDto entityBoToExportDto(DictionaryBo entityBo);

    @Override
    public abstract DictionaryBo importDtoToEntityBo(DictionaryImportDto importDto);

    @Override
    public abstract List<DictionaryBo> importDtoToEntityBo(List<DictionaryImportDto> importDto);


    @AfterMapping
    public void afterMappingEntityBoToEntity(@MappingTarget Dictionary dictionary, DictionaryBo dictionaryBo) {
        // entityBoToEntity() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityBoToEntity()
    }

    @AfterMapping
    public void afterMappingEntityToEntityBo(@MappingTarget DictionaryBo dictionaryBo, Dictionary dictionary) {
        // entityToEntityBo() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityToEntityBo()
    }

    @AfterMapping
    public void afterMappingQueryRequestToQuery(@MappingTarget DictionaryQuery dictionaryQuery, DictionaryQueryRequest dictionaryQueryRequest) {
        // queryRequestToQuery() 内部其它代码执行完之后，最后会自动执行 afterMappingQueryRequestToQuery()
    }

    @AfterMapping
    public void afterMappingEntityBoToQueryResponse(@MappingTarget DictionaryQueryResponse dictionaryQueryResponse, DictionaryBo dictionaryBo) {
        // entityBoToQueryResponse() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityBoToQueryResponse()
    }

    @AfterMapping
    public void afterMappingEntityBoToSaveResponse(@MappingTarget DictionarySaveResponse dictionarySaveResponse, DictionaryBo dictionaryBo) {
        // entityBoToSaveResponse() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityBoToSaveResponse()
    }

    @AfterMapping
    public void afterMappingSaveRequestToEntityBo(@MappingTarget DictionaryBo dictionaryBo, DictionarySaveRequest dictionarySaveRequest) {
        // saveRequestToEntityBo() 内部其它代码执行完之后，最后会自动执行 afterMappingSaveRequestToEntityBo()
    }

    @AfterMapping
    public void afterMappingEntityBoToUpdateResponse(@MappingTarget DictionaryUpdateResponse dictionaryUpdateResponse, DictionaryBo dictionaryBo) {
        // entityBoToUpdateResponse() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityBoToUpdateResponse()
    }

    @AfterMapping
    public void afterMappingUpdateRequestToEntityBo(@MappingTarget DictionaryBo dictionaryBo, DictionaryUpdateRequest dictionaryUpdateRequest) {
        // updateRequestToEntityBo() 内部其它代码执行完之后，最后会自动执行 afterMappingUpdateRequestToEntityBo()
    }

    @AfterMapping
    public void afterMappingImportDtoToEntityBo(@MappingTarget DictionaryBo dictionaryBo, DictionaryImportDto dictionaryImportDto) {
        // importDtoToEntityBo() 内部其它代码执行完之后，最后会自动执行 afterMappingImportDtoToEntityBo()
    }

    @AfterMapping
    public void afterMappingEntityBoToExportDto(@MappingTarget DictionaryExportDto dictionaryExportDto, DictionaryBo dictionaryBo) {
        // entityBoToExportDto() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityBoToExportDto()
    }

    public Integer statusEnumToInteger(StatusEnum statusEnum) {
        if (Objects.isNull(statusEnum)) {
            return null;
        }
        return statusEnum.getCode();
    }

    public StatusEnum integerToStatusEnum(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }
        return StatusEnum.of(code);
    }
}
